import java.util.Random;

public class Demo7 {
    public static int[] nums = new int[(int)1e9];
    public static long sum1, sum2, sum;
    public static void main(String[] args) throws InterruptedException {
        Random random = new Random();
        for(int i = 0; i < (int)1e9; i++) nums[i] = random.nextInt(100) + 1;    //生成1-100的整数
        double startTime = System.currentTimeMillis();
        Thread t1 = new Thread(() -> {
            for(int i = 0; i < nums.length; i += 2)
                sum1 += nums[i];
        });

        Thread t2 = new Thread(() -> {
            for(int i = 1; i < nums.length; i += 2)
                sum2 += nums[i];
        });

        t1.start();
        t2.start();
        t1.join();
        t2.join();

        sum = sum1 + sum2;
        double endTime = System.currentTimeMillis();
        System.out.println("偶数下标和为: " + sum1);
        System.out.println("奇数下标和为: " + sum2);
        System.out.println("总和为: " + sum);
        System.out.println("运行时间为: " + (endTime - startTime));

    }
}
